    	$(function(){
    		//初始化
    		$.post("model.action",function(data){
    	    	$("#model").append(data);
    	    });
    		$.post("venueType.action",function(data){
    	    	$("#venue_type").append(data);
    	    });
    		$.post("city.action",function(data){
    	    	$("#city").append(data);
    	    });
    		$.post("region.action",function(data){
    	    	$("#region").append(data);
    	    });
    		
    		//调用ajax返回数据库数据，实现自动补全	 
			$.post("auto.action",{name:7},function(data){
					var item=eval("("+data+")");
			 		$("#qbx_number").autocomplete(item,option);
			});
			$.post("auto.action",{name:8},function(data){
					var item=eval("("+data+")");
			 		$("#alona_number").autocomplete(item,option);
			});
			$.post("auto.action",{name:5},function(data){
					var item=eval("("+data+")");
			 		$("#venue_code").autocomplete(item,option);
			});	 
			$.post("auto.action",{name:6},function(data){
					var is=eval("("+data+")");
				 	$(".item").each(function(){
				 		$(this).autocomplete(is,option1);
				 	});
			});
			
    		//自动补全选项			 
 			var option={
			 	minChars: 1,  
       			autoFill: true,   
        		matchContains: true,
        		//mustMatch:true,  
        		formatItem: function(data, i, total) {  
            		return "<I>"+data.name+"</I>";  
        		},  
        		formatMatch: function(data, i, total) {  
            		return data.name;  
        		},  
        		formatResult: function(data) {  
            		return data.name;  
        		}
			};
 			
 			//自动补全选项			 
 			var option1={
			 	minChars: 1,  
       			autoFill: true,   
        		matchContains: true,
        		mustMatch:true,  
        		formatItem: function(data, i, total) {  
            		return "<I>"+data.name+"</I>";  
        		},  
        		formatMatch: function(data, i, total) {  
            		return data.name;  
        		},  
        		formatResult: function(data) {  
            		return data.name;  
        		}
			};
 			
 			//限制输入为数字
 			$("#s_aisles,#s_unit").numeric({allow:"."});
 			 
 			//查询条件处理
 			var type="all";
 			$("#form1 select").each(function(){
 				$(this).change(function(){
 					$("input").val("");
 					type="above";
 				});
 				
 			});
 			$("#form1 input").each(function(){
 				$(this).keyup(function(){
 					var $this=$(this);
 					var value=$this.val();
 					$("select").val("All");
 					$("input").val("");
 					$this.val(value);
 					type="bellow";					
 				});
 				
 			});
 			
 			//查询VM
 			$("#search").click(function(){
 				var bool1=true;
 				var bool2=true;
 		  		$("#form1 input").each(function(){
 		  			if($(this).val()!="")
 		  			{
 		  				bool1=false;
 		  				return;
 		  			}
 		  		});
 		  		$("#form1 select").each(function(){
 		  			if($(this).val()!="All")
 		  			{
 		  				bool2=false;
 		  				return;
 		  			}
 		  		});
 				if(bool1&&bool2)
 				{
 					type="all";
 					$( "#dialog-form4" ).dialog( "open" );
 		  			if ($.browser.msie) {           
 		  				$("#dialog-form4").css("height", 100);                
 					} 
 				}
 				else
 					PerformSearch();
 			});
 			
 			function PerformSearch()
 			{
 				var url="searchVM.action?type="+type+"&"+$("#form1").serialize();
 				$("#content").show();
 				$("#content").dataTable({
 					"bJQueryUI": true,
 					"sPaginationType": "full_numbers",
 					"bProcessing":true,
 					"sAjaxSource":url,			
 					"bDestroy":true,
 					"sDom":'CT<"clear">R<"H"lfr>t<"F"ip>',
 					"oTableTools":{
 						"sSwfPath":"../../JavaScript/DataTables/extras/TableTools/media/swf/copy_cvs_xls_pdf.swf"
 						},
 					"oColVis": {
 								"buttonText": "Change columns"
 							}
 				});
 			}
 			
 			//编辑VM信息
 		    $("#editOne").live("click", function(){
 		        var ID=$(this).attr("value");
 		      	$("#s_id").val(ID);
 		 		$("#s_qbxNumber").val($(this).parent().parent().find("td").eq(1).text());
 		 		$("#s_alonaNumber").val($(this).parent().parent().find("td").eq(2).text());
 		 		$("#s_aisles").val($(this).parent().parent().find("td").eq(3).text());
 		 		$("#s_model").val($(this).parent().parent().find("td").eq(4).text());
 		 		$("#s_code").val($(this).parent().parent().find("td").eq(5).text());
 		 		$("#s_type").val($(this).parent().parent().find("td").eq(6).text());
 		 		$("#s_unit").val($(this).parent().parent().find("td").eq(7).text());
 		 		$("#s_city").val($(this).parent().parent().find("td").eq(8).text());
 		 		$("#s_region").val($(this).parent().parent().find("td").eq(9).text());
 		    	$( "#dialog-form1" ).dialog( "open" );
 		    	if ($.browser.msie) {           
 		    		$("#dialog-form1").css("height", 300);                
 		  	}    	
 		    });
 		    
 		   /*-----输入验证-----*/
			//验证VM是否已存在
			var checkValue=[true,true,true];
			function CheckQBXNumber(temp,i)
			{
				var content=$("#"+temp).val();
				if(content!=null&&content!="")
				{
					$.post("checkVM.action",{
						id:i,
						value:content
					},function(data){
						if(data=="error")
						{
							$("#f"+i).html("Lost connection with server");
							checkValue[i]=false;
						}
						else if(data=="false"||data==$("#s_id").val())
						{
							$("#f"+i).html("");
							checkValue[i]=true;
						}
						else
						{
							$("#f"+i).html("This machine has already exists");
							checkValue[i]=false;
						}
					});				
				}
			}
			
			$("#s_qbxNumber").keyup(function(){CheckQBXNumber("qbx_number",0);});
			$("#s_alonaNumber").keyup(function(){CheckQBXNumber("alona_number",1);});
			$("#s_code").keyup(function(){CheckQBXNumber("venue_code",2);});
			/*-----输入验证-----*/
 		    
 		    
 		    //删除商品记录
 		    $("#deleteOne").live("click", function(){
 		      var ID=$(this).attr("value");
 		      $("#d_id").val(ID);
 		      $( "#dialog-form2" ).dialog( "open" );
 		      if($.browser.msie) {           
 		    	  $("#dialog-form2").css("height", 100);                
 		  	  } 
 		    });
 		  	
 		  	//勾选全部
 		  	$("#selectAll").click(function(){
 		  		var checkBool=false;
 		  		if($(this).attr("checked"))
 		  			checkBool=true;
 		  		$(".checkOne").each(function(){
 		  			$(this).attr("checked",checkBool);
 		  		});
 		  	});
 		  	
 		  	//删除多项
 		  	var deleteItems;
 		  	$("#delete").click(function(){
 		  		deleteItems="";
 		  		$(".checkOne").each(function(){
 		  			if($(this).attr("checked"))
 		  				deleteItems+=$(this).attr("value")+"#";
 		  		});
 		  		if(deleteItems=="")
 		  		{
 		  			alert("You have not select the items");
 		  			return;
 		  		}
 		  		deleteItems=deleteItems.substring(0,deleteItems.length-1);
 		  		var temp=deleteItems.split("#");
 		  		$("#dialog-form3 p").html(temp.length.toString()+" Products information will be deleted");
 		 		$( "#dialog-form3" ).dialog( "open" );
 		 		if ($.browser.msie) {           
 		  			$("#dialog-form3").css("height", 100);                
 				}
 		  	});
 			
 			/*-----提示对话框 -----*/
 		  	//更新对话框	
 		  	$( "#dialog-form1" ).dialog({
 					autoOpen: false,
 					height: 450,
 					width: 600,
 					modal: true,			
 					buttons: {
 						"Continue": function() {
 							//判断输入是否为空
 			    			var temp=true;
 			    			$("#form3 input").each(function(){
 			    				if($(this).val()==""||$(this).val()==undefined)
 			    				{
 			    					temp=false;
 			    					return;
 			    				}
 			    			}); 
 			    			if(!temp)
 			    				alert("All form files are required");
 			    			else if(checkValue[0]&&checkValue[1]&&checkValue[2])
 			    			{
 			    				$.post("searchAisles.action",{id:$("#s_id").val()},function(data){
 			    					data=eval("("+data+")");
 			    					for(var i in data)
 			    					{
 			    						var newAisles = data[i];
 			    						$("#I"+newAisles.aisles).val(newAisles.product);
 			    						$("#P"+newAisles.aisles).val(newAisles.price);
 			    					}
 			    				});
 			    				$("#dialog-form5").dialog( "open" );
 			    	 		    if($.browser.msie) {           
 			    	 		    	$("#dialog-form5").css("height", 600);                
 			    	 		  	} 
 			    	 		    $("#dialog-form1").dialog("close");
 			    			}
 			    			else
 			    				alert("This machine has already exists");	
 						},
 						Cancel: function() {
 							$( this ).dialog( "close" );
 						}
 					},
 					close: function() {
 						allFields.val( "" ).removeClass( "ui-state-error" );
 					}
 				});
 				
 				//删除对话框
 				$( "#dialog-form2" ).dialog({
 					autoOpen: false,
 					height: 250,
 					width: 500,
 					modal: true,
 					buttons: {
 						"Continue": function() {
 							$.post("delVM.action",{id:$("#d_id").val()},function(data){
 		  						if(data=="false")
 		  							alert("Delete Failed");
 		  						else if(data=="error")
 		  							alert("Lost connection to the server");
 		  						PerformSearch();
 		  						$( "#dialog-form2" ).dialog( "close" );
 		  					});
 						},
 						Cancel: function() {
 							$( this ).dialog( "close" );
 						}
 					},
 						close: function() {
 							allFields.val( "" ).removeClass( "ui-state-error" );
 						}
 				});
 				
 				//删除多项对话框
 				$( "#dialog-form3" ).dialog({
 					autoOpen: false,
 					height: 250,
 					width: 500,
 					modal: true,
 					buttons: {
 						"Continue": function() {						
 								$.post("delMoreVM.action",{id:deleteItems},function(data){
 		  						if(data=="false")
 		  						{
 		  							alert("Delete Failed");
 		  							return;
 		  						}
 		  						else if(data=="error")
 		  						{
 		  							alert("Lost connection to the server");
 									return;
 								}
 								PerformSearch();
 		  						$( "#dialog-form3" ).dialog( "close" );
 								
 		  					});
 		  					
 						},
 						Cancel: function() {
 							$( this ).dialog( "close" );
 						}
 					},
 						close: function() {
 							allFields.val( "" ).removeClass( "ui-state-error" );
 						}
 				});
 				
 				//无条件查询对话框
 				$("#dialog-form4" ).dialog({
 					autoOpen: false,
 					height: 250,
 					width: 500,
 					modal: true,
 					buttons: {
 						"Continue": function() {
 							PerformSearch();
 							$(this).dialog("close");
 						},
 						Cancel: function() {
 							$( this ).dialog( "close" );
 						}
 					},
 						close: function() {
 							allFields.val( "" ).removeClass( "ui-state-error" );
 						}
 				});
 				
 				//Aisles更新窗口
 				$( "#dialog-form5" ).dialog({
 					autoOpen: false,
 					height: 650,
 					width: 1400,
 					modal: true,
 					buttons: {
 						"Back":function(){
 							$("#dialog-form1").dialog("open");
 			 		    	if ($.browser.msie) {           
 			 		    		$("#dialog-form1").css("height", 300);
 			 		    	}
 			 		    	$(this).dialog("close");
 						},
 						"Update": function() {
 							var bool=true;
 			    			var i=0;
 			    			for(i=1;i<57;i++)
 			    			{
 			    				var item=$("#I"+i).val();
 			    				var price=$("#P"+i).val();
 			    				if((item!=""&&(price==""||price==null))||((item==null||item=="")&&price!=""))
 			    					bool=bool&false;
 			    			}
 			    			if(!bool)
 			    				alert("The Item and Price not matched");
 			    			else
 			    			{
 			    				$.post("updateVM.action",$("#form3").serialize()+"&"+$("#form5").serialize(),function(data){
 			   					if(data=="success")
 			   					{
 			   						alert("Update the VM information succeed");
 			   						PerformSearch();
 			   					}
 			   					else
 			   						alert("Update the VM information Failed");
 			   				});
 			    			}
 							$(this).dialog("close");
 						},
 						Cancel: function() {
 							$( this ).dialog( "close" );
 						}
 					},
 						close: function() {
 							allFields.val( "" ).removeClass( "ui-state-error" );
 						}
 				});
    	});